Implementation of the reciprocal square root in MPFR

نویسنده

  • Paul Zimmermann
چکیده

We describe the implementation of the reciprocal square root — also called inverse square root — as a native function in the MPFR library. The difficulty is to implement Newton’s iteration for the reciprocal square root on top’s of GNU MP’s mpn layer, while guaranteeing a rigorous 1/2 ulp bound on the roundoff error. The reciprocal square root is an important function in 3D graphics, for the normalization of 3D vectors, and as such has received much attention in the literature [5]. Indeed, given (x, y, z), compute t = x2 + y2 + z2, u = t−1/2, x′ = ux, y′ = uy, z′ = uz, then (x′, y′, z′) is a normalized vector with x′2 + y′2 + z′2 = 1. A nice implementation attributed to Greg Walsh by Wikipedia is the following: float invSqrt(float x) { float xhalf = 0.5f*x; int i = *(int *)&x; i = 0x5f3759df (i >> 1); x = *(float *)&i; x = x * (1.5f xhalf * x * x); return x; } See also IBM’s US patent 6654777 (Single precision inverse square root generator) issued on November 25, 2003. The reciprocal square root is an interesting function per se, since it can be computed with Newton’s iteration without any division, similarly to the reciprocal. Karp and Markstein have shown how the square root can be efficiently computed, by modifying the last Newton iteration of the reciprocal square root [4]. In the context of the MPFR library [2], our aim is to provide a native implementation of the reciprocal square root which guarantees correct rounding. By “native implementation”, we mean it should rely on the GMP mpn layer only, which provides operations on arrays of words (addition, subtraction, multiplication) [3]. MPFR reciprocal square root (function mpfr rec sqrt) is based on Ziv’s strategy and the mpfr mpn rec sqrt function, which given a precision p, and an input 1 ≤ A < 4, returns an approximation x satisfying x− 1 2 · 2−p ≤ A−1/2 ≤ x+ 2−p. The mpfr mpn rec sqrt function is based on Newton’s iteration and the following lemma [1]: Date: March 2008. Centre de Recherche INRIA Nancy Grand Est, Projet CACAO Bâtiment A, 615 rue du Jardin Botanique, F-54602 Villers-lès-Nancy Cedex, [email protected].

برای دانلود رایگان متن کامل این مقاله و بیش از 32 میلیون مقاله دیگر ابتدا ثبت نام کنید

ثبت نام

اگر عضو سایت هستید لطفا وارد حساب کاربری خود شوید

منابع مشابه

The Mpfr Library: Algorithms and Proofs

1. Notations and Assumptions 2 2. Error calculus 2 2.1. Ulp calculus 2 2.2. Relative error analysis 4 2.3. Generic error of addition/subtraction 4 2.4. Generic error of multiplication 5 2.5. Generic error of inverse 5 2.6. Generic error of division 6 2.7. Generic error of square root 7 2.8. Generic error of the exponential 7 2.9. Generic error of the logarithm 8 2.10. Ulp calculus vs relative e...

متن کامل

The Mpfr Library: Algorithms and Proofs

1. Error calculus 2 1.1. Ulp calculus 2 1.2. Relative error analysis 4 1.3. Generic error of addition/subtraction 4 1.4. Generic error of multiplication 5 1.5. Generic error of inverse 5 1.6. Generic error of division 6 1.7. Generic error of square root 7 1.8. Generic error of the exponential 7 1.9. Generic error of the logarithm 8 1.10. Ulp calculus vs relative error 9 2. Low level functions 9...

متن کامل

High-Speed Double-Precision Computation of Reciprocal, Division, Square Root and Inverse Square Root

A new method for the high-speed computation of double-precision floating-point reciprocal, division, square root, and inverse square root operations is presented in this paper. This method employs a second-degree minimax polynomial approximation to obtain an accurate initial estimate of the reciprocal and the inverse square root values, and then performs a modified Goldschmidt iteration. The hi...

متن کامل

Reduction of Look Up Tables for Computation of Reciprocal of Square Roots

Among many existing algorithms, convergence methods are the most popular means of computing square root and the reciprocal of square root of numbers. An initial approximation is required in these methods. Look up tables (LUT) are employed to produce the initial approximation. In this paper a number of methods are suggested to reduce the size of the look up tables. The precision of the initial a...

متن کامل

Class-AB Square-Root Domain Filters Based on the Floating

In this paper a new approach for design of class-AB current-mode square-root domain filters based on the electronically simulated translinear loop principle is presented. FG-MOS transistors that operate in strong inverted saturation region are employed for implementation of translinear loop circuit. The filter achieves immunity to body effect, low circuit complexity, large input dynamic ran...

متن کامل

ذخیره در منابع من


  با ذخیره ی این منبع در منابع من، دسترسی به آن را برای استفاده های بعدی آسان تر کنید

عنوان ژورنال:

دوره   شماره 

صفحات  -

تاریخ انتشار 2008